<template>
  <div>
       <van-nav-bar
        title="订单详情"
        left-text="返回"
        
        left-arrow
        @click-left="$router.go(-1)"
       
        />
        <van-search v-model="keyword" placeholder="请输入搜索关键词" />
      <van-collapse v-model="activeName" accordion>
      <van-collapse-item :title="v.order_time" :name="v.oid" v-for="v in searchList" :key="v.oid">
        <van-cell :title="v.user" icon="manager" />
        <van-cell :title="v.tel" icon="phone" />
        <van-cell :title="v.address" icon="location" />
        <van-cell :title="v.total_price" icon="gold-coin" />
        <van-card
              v-for="it,index in v.goods"
              :key="index"
              :price="it.price+'.00'"
             
              :title="it.tname"
              :thumb="it.timg"
            />
      </van-collapse-item>
    
     </van-collapse>

  </div>
</template>
<script>
import {OrderDet}  from "@/utils/api"
import {get} from "@/utils/local"
export default {
  data() {
    return {
       orderList:[],
       activeName:'',
       keyword:''
    }
  },
  mounted(){
     this.getOrder()
  },

  computed:{
      searchList(){
        // name
       return this.orderList.filter(v=>{
          // 满足关键字的数组 关键字和user  
          // eval("("+`var reg= /${this.keyword}/g`+")")
          let reg=new RegExp(this.keyword,"g")
          // 匹配 v.user
          // console.log(reg);
          let res=reg.test(v.user)||reg.test(v.tel)// true false
          return res
        })
        // return []
      }
  },
  methods:{
     getOrder(){
        let uid=get("userinfo").uid
        let params={
          uid
        }
        OrderDet(params)
        .then(res=>{
            console.log(res);
            if(res.code==200){
              this.orderList=res.data.sort((a,b)=>b.oid-a.oid).slice(0,30)
            }
        })
     }
  },
}
</script>
<style scoped>

</style>
